package org.whatever.aha.zjut.platform.service.project;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.whatever.aha.zjut.platform.entity.project.ProjectReturnLog;
import org.whatever.aha.zjut.platform.entity.school.ProjectScore;
import org.whatever.aha.zjut.platform.mapper.project.ProjectReturnLogMapper;

/**
 * @author Vc
 * @version 1.0
 * @Desc
 * @date 2021/11/16 20:55
 */
@RequiredArgsConstructor
@Service
public class ProjectReturnLogService {
    final ProjectReturnLogMapper projectReturnLogMapper;

    /**
     * 加入一条退回记录
     *
     * @param projectReturnLog
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation= Propagation.REQUIRED)
    int addRerutnLog(ProjectReturnLog projectReturnLog){
        return projectReturnLogMapper.insert(projectReturnLog);
    }

    /**
     * 获取最新的退回修改记录
     *
     * @param projectId
     * @param stageId
     * @return
     */
    public ProjectReturnLog getNewestProjectReturnLog(int projectId, int stageId){
        return projectReturnLogMapper.selectOne(new QueryWrapper<ProjectReturnLog>().eq("project_id", projectId).eq("stage_id", stageId).orderByDesc("return_date").last("limit 1"));
    }

    /**
     * 根据阶段id删除退回修改信息
     *
     * @param stageId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation= Propagation.REQUIRED)
    public Integer deleteReturnLogByStageId(int stageId){
        return projectReturnLogMapper.delete(new QueryWrapper<ProjectReturnLog>().eq("stage_id", stageId));
    }
}
